{extend name="../../admin/view/main"}

{block name="content"}
{include file='shop/goods/formstyle'}
<form autocomplete="off" class='layui-form layui-card' data-auto="true" id="GoodsForm" method="post" onsubmit="return false;">
    <div class="layui-card-body padding-40 padding-bottom-20">

        <fieldset class="layui-form-item">
            <legend><span class="layui-badge layui-bg-cyan">选择业务员</span></legend>
            <div class="layui-form-item layui-row layui-col-space15">
                <div class="layui-col-xs6 block relative">
                    <b class="color-green label-required-prev">业务员</b>
                    <select class="layui-select" lay-search name="staff_id">
                        <option value="0">请选择业务员</option>
                        {foreach $staff_list as $staff}{if isset($vo.staff_id) and $staff.id eq $vo.staff_id}
                        <option selected value="{$staff.id}">{$staff.name}</option>
                        {else}
                        <option value="{$staff.id}">{$staff.name}</option>
                        {/if}
                        {/foreach}
                    </select>
                </div>
            </div>
        </fieldset>

        <div class="hr-line-dashed margin-top-40"></div>

        <fieldset class="layui-form-item">
            <legend><span class="layui-badge layui-bg-cyan">客户</span></legend>
            <div class="layui-form-item layui-row layui-col-space15">
                <div class="layui-col-xs4 block relative">
                    <b class="color-green label-required-prev">姓名</b><span class="margin-left-5 color-desc">Name</span>
                    <input class="layui-input" name="name" placeholder="请输入客户名称" required  value="{$vo.name|default=''}">
                </div>
                <label class="layui-col-xs4 block relative">
                    <b class="color-green label">联系方式</b><span class="margin-left-5 color-desc">Phone</span>
                    <input class="layui-input" name="phone" placeholder="请输入手机号" value="{$vo.phone|default=''}">
                </label>
                <label class="layui-col-xs4 block relative">
                    <b class="color-green label">身份证号</b><span class="margin-left-5 color-desc">IdCard</span>
                    <input class="layui-input" name="idcard" placeholder="请输入身份证号" value="{$vo.idcard|default=''}">
                </label>
            </div>
            <div class="layui-form-item layui-row layui-col-space15">
                <div class="layui-col-xs6 block relative">
                    <b class="color-green label-required-prev">开户行</b><span class="margin-left-5 color-desc">银行卡的开户卡</span>
                    <input class="layui-input" name="account_bank" placeholder="请输入开户行" required value="{$vo.account_bank|default=''}">
                </div>
                <label class="layui-col-xs6 block relative">
                    <b class="color-green label-required-prev">收款卡号</b><span class="margin-left-5 color-desc">给客户的打款卡号</span>
                    <input class="layui-input" name="bank_no" placeholder="请输入收款卡号" required value="{$vo.bank_no|default=''}">
                </label>
                <label class="layui-col-xs6 block relative">
                    <b class="color-green label-required-prev">客户编号</b><span class="margin-left-5 color-desc">客户编号</span>
                    <input class="layui-input" name="customer_no" placeholder="请输入客户编号" required value="{$vo.customer_no|default=''}">
                </label>
                <label class="layui-col-xs6 block relative">
                    <b class="color-green label-required-prev">合同编号</b><span class="margin-left-5 color-desc">合同编号</span>
                    <input class="layui-input" name="contract_no" placeholder="请输入合同编号" required value="{$vo.contract_no|default=''}">
                </label>
            </div>
        </fieldset>
        <div class="hr-line-dashed margin-top-40"></div>

        <fieldset class="layui-form-item">
            <legend><span class="layui-badge layui-bg-cyan">投资产品</span></legend>
            <div class="layui-form-item layui-row layui-col-space15">
                <div class="layui-col-xs3 block relative">
                    <b class="color-green label-required-prev">选择产品</b>
                    {if isset($vo.goods_id)}
                    <div class="text-left padding-5">
                        <span class="layui-badge">{$vo.company_name}----{$vo.cate_name}----{$vo.name}</span>
                    </div>
                    {else}
                        <select class="layui-select" lay-search name="goods_id" lay-filter="goods_id">
                            <option value="0">请选择产品</option>
                            {foreach $goods_list as $goods}
                            <option value="{$goods.id}">{$goods.company_name}----{$goods.cate_name}----{$goods.name}</option>
                            {/foreach}
                        </select>
                    {/if}
                </div>
                <label class="layui-col-xs3 block relative">
                    <b class="color-green label-required-prev">年利率</b><span class="margin-left-5 color-desc">Rate</span>
                    <div class="text-left padding-5">
                        <span class="layui-badge layui-bg-orange" id="annual_rate">{$vo.goods_annual_rate|default=0}%</span>
                    </div>
                </label>
                <label class="layui-col-xs3 block relative">
                    <b class="color-green label-required-prev">投资时间</b><span class="margin-left-5 color-desc">Time</span>
                    <div class="text-left padding-5">
                        <span class="layui-badge layui-bg-green" id="time_number">{$vo.goods_time_number|default=0}</span><span class="layui-badge layui-bg-blue" id="time_type">
                        {if !empty($v)}
                            {switch $vo.goods_time_type}
                            {case 1 }月{/case}
                            {case 2 }季{/case}
                            {case 3 }年{/case}
                            {case 4 }天{/case}
                            {/switch}
                        {else}
                            年
                        {/if}
                        </span>
                    </div>
                </label>
                <label class="layui-col-xs3 block relative">
                    <b class="color-green label-required-prev">返息规则</b><span class="margin-left-5 color-desc">Rule</span>
                    <div class="text-left padding-5">
                        <span class="layui-badge" id="return_rule">
                            {if (isset($vo.goods_return_rule))}
                                {if $vo.goods_return_rule eq 1}
                                    月返息
                                {else}
                                    到期返
                                {/if}
                            {/if}
                        </span>
                    </div>
                </label>
            </div>

            <div class="layui-form-item layui-row layui-col-space15">
                <div class="layui-col-xs3 block relative">
                    <b class="color-green label-required-prev">付款方式</b>
                    <select class="layui-select" lay-search name="payment_method">
                        <option value="-1">请选择付款方式</option>
                        {foreach ['0'=>'划卡','1'=>'转账','2'=>'现金','3'=>'续投'] as $k=>$v}{if isset($vo.payment_method) and  $k eq $vo.payment_method}
                        <option selected value="{$k}">{$v}</option>
                        {else}
                        <option value="{$k}">{$v}</option>
                        {/if}
                        {/foreach}
                    </select>
                </div>
                <label class="layui-col-xs3 block relative">
                    <b class="color-green label-required-prev">投资日期</b><span class="margin-left-5 color-desc">Time</span>
                    {if isset($vo.invest_date)}
                    <div class="padding-5">
                        {$vo.invest_date}
                    </div>
                    {else}
                    <input type="text" class="layui-input" id="test1" name="invest_date" placeholder="yyyy-MM-dd">
                    {/if}
                </label>
                <label class="layui-col-xs3 block relative">
                    <b class="color-green label-required-prev">起息日期</b><span class="margin-left-5 color-desc">Time</span>
                    {if isset($vo.start_at)}
                    <div class="padding-5">
                        {$vo.start_at}
                    </div>
                    {else}
                    <input type="text" class="layui-input" id="test2" name="start_at" placeholder="yyyy-MM-dd">
                    {/if}
                </label>
                <label class="layui-col-xs3 block relative">
                    <b class="color-green label-required-prev">投资金额</b><span class="margin-left-5 color-desc">Rate</span>
                    {if isset($vo.money)}
                    <div class="padding-5">
                        {$vo.money}元
                    </div>
                    {else}
                    <input class="layui-input" required type="number" value="" data-value-min="0.01" name="money" autocomplete="off" placeholder="请输入要投资的金额">
                    {/if}
                </label>
            </div>
        </fieldset>
        <div class="hr-line-dashed margin-top-40"></div>
        {notempty name='vo.id'}<input name="id" type="hidden" value="{$vo.id}">{/notempty}
        <div class="layui-form-item text-center">
            <button class="layui-btn layui-btn-danger" onclick="pageBack()" type="button">返回</button>
            <button class="layui-btn" type="submit">保存记录</button>
        </div>

    </div>
</form>
{/block}

{block name='script'}

<script>
    /*! 表单初始化 */

    var checkProperty = [];
    var _rule = {};

    window.form.render();

    let goods_list = {:json_encode($goods_list)};

    $(function (){
        form.on('select(goods_id)', function (data){
            let goods_id = data.value;
            if(goods_id == 0){
                $("#annual_rate").html('0%')
                $("#time_number").html('0')
                $("#time_type").html('天')
                $("#return_rule").html('')
                return;
            }
            $.each(goods_list, function() {
                if(this.id == goods_id){
                    $("#annual_rate").html(this.annual_rate+'%')
                    $("#time_number").html(this.time_number)
                    let time;
                    switch (this.time_type){
                        case 1:
                            time = '月';
                            break;
                        case 2:
                            time = '季';
                            break;
                        case 3:
                            time = '年';
                            break;
                        case 4:
                            time = '天';
                            break;
                    }
                    $("#time_type").html(time)
                    if(this.return_rule === 1){
                        $("#return_rule").html('按月返')
                    }else{
                        $("#return_rule").html('到期返')
                    }
                }

            });
        })
    })
    function pageBack () {
        history.back(), $.msg.close();
    };
    layui.use('laydate', function(){
        var laydate = layui.laydate;

        //常规用法
        laydate.render({
            elem: '#test1'
        });
        //常规用法
        laydate.render({
            elem: '#test2'
        });

    });

</script>
{/block}